function  [flowsol]=uzawa(A,B,f,g,maxit,tol)
% uzawa iteration for saddle problem
%[A B^T]--[f]
%[B 0  ]--[g]
% maxit  maximum iteration count
% error tol
%
if nargin<6 
    error('parameter missing!');
end
  
  
iter_n=0;
uptol=20;
m=length(f);
n=length(g);
u=sparse(m,1);
p=sparse(n,1);

R=cholinc(sparse(A),0.1); %approximation of matrix of 
Ainv=inv(R)*inv(R');
tao=eigs(B*Ainv*B',1);

while (iter_n<maxit && uptol>tol)
    iter_n=iter_n+1;
     %      du=A\(f-B'*p)-u;
    du = minres(A,(f-B'*p),1e-7,50,R,R',u)-u;
     u=u+du;
    dp=1/1.5/tao*(B*u-g);
     p=p+dp;
    uptol=norm(dp)+norm(du);
end
flowsol=[u;p];


